import { BeforeInsert, BeforeUpdate, Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Article } from "../article/article.entity";

@Entity()
export class Classify {
    @PrimaryGeneratedColumn({
        comment:'主键id'
    })
    id: number;

    @Column({
        comment:'父级id'
    })
    pid: number;

    @Column({
        comment:'分类名'
    })
    name: string;

    @Column({
        nullable: true,
        comment:'分类描述'
    })
    desc: string;

    @Column({
        comment:'排序'
    })
    sort: number;

    @Column({
        type: 'tinyint',
        comment:'状态 1显示 0隐藏'
    })
    status: number;

    @Column({
        nullable: true,
        comment:'图标'
    })
    icon: string;
    
    @Column({
        type: 'bigint',
        update:false,
        comment:'创建时间'
    })
    create_time: number;

    @Column({
        type: 'bigint',
        comment:'修改时间'
    })
    update_time: number;

    @BeforeInsert()
    beforeInsert() {
        this.create_time = new Date().getTime();
        this.update_time = new Date().getTime();
    }

    @BeforeUpdate()
    beforeUpdate() {
        this.update_time = new Date().getTime();
    }

    @OneToMany(() => Article, (articles) => articles.classify)
    articles: Article[];
}
